package com.ark.yygh.hosp.controller.api;

import com.ark.yygh.common.result.Result;
import com.ark.yygh.hosp.service.DepartmentService;
import com.ark.yygh.hosp.service.HospitalService;
import com.ark.yygh.model.hosp.Hospital;
import com.ark.yygh.vo.hosp.DepartmentVo;
import com.ark.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "医院管理前台接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("查询医院列表")
    @GetMapping("/findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalPage = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @ApiOperation("根据医院名称模糊查询")
    @GetMapping("/findByHosname/{hosname}")
    public Result findByHosName(@PathVariable String hosname){
        List<Hospital> list = hospitalService.findByHosname(hosname);
        return Result.ok(list);
    }

    @ApiOperation("医院预约挂号详情")
    @GetMapping("/{hoscode}")
    public Result item(@PathVariable String hoscode){
        Map<String, Object> item = hospitalService.item(hoscode);
        return Result.ok(item);
    }

    @ApiOperation("获取科室列表")
    @GetMapping("/departmentList/{hoscode}")
    public Result departmentList(@PathVariable String hoscode){
        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return Result.ok(list);
    }
}
